#include <iostream>
#include <cstring>
using namespace std;

class String
{
public:
    char *str;
    String(const char *p)
    {
        int len = std::strlen(p);
        str = new char[len + 1];
        for (int i = 0; i < len; i++)
        {
            str[i] = p[i];
        }
    }
    ~String()
    {
        delete[] str;
    }
    char getPos(int num)
    {
        return str[num];
    }
    // []运算符重载
    char operator[](int num)
    {
        return str[num];
    }
};
int main()
{
    String s1("123");
    cout << s1.str << endl;
    cout << s1.getPos(1) << endl;
    cout << s1.operator[](1) << endl;
    cout << s1[1] << endl;
}
